#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct Node
{
    int num, p;
    Node( ) { }
    Node( int _num, int _p )
        : num( _num ), p( _p ) { }
};

bool operator < ( const Node &x, const Node &y )
{
    return x.p < y.p;
}

int n, m;
vector<int> a[ 100000 ];

void init( )
{
    int i, t;
    for ( i = 0; i < n; i++ )
        a[ i ].clear( );
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &t);
        a[ t ].push_back( i );
    }
}

void work( )
{
    int i, j, q, b[ 100 ], t, c, cnt[ 100 ], count, minn;
    Node v[ 100000 ];
    while ( m-- )
    {
        scanf("%d", &q);
        if ( q == 0 )
        {
            puts("0");
            continue;
        }
        for ( i = 0; i < q; i++ )
            scanf("%d", &b[ i ]);
        sort( b, b + q );
        c = 0;
        for ( i = 0; i < a[ b[ 0 ] ].size( ); i++ )
            v[ c++ ] = Node( 0, a[ b[ 0 ] ][ i ] );
        t = 1;
        for ( i = 1; i < q; i++ )
            if ( b[ i ] != b[ i - 1 ] )
            {
                for ( j = 0; j < a[ b[ i ] ].size( ); j++ )
                    v[ c++ ] = Node( t, a[ b[ i ] ][ j ] );
                t++;
            }
        if ( t == 1 )
        {
            puts("1");
            continue;
        }
        sort( v, v + c );
        for ( i = 0; i < t; i++ )
            cnt[ i ] = 0;
        i = j = 0;
        cnt[ v[ 0 ].num ]++;
        count = 1;
        minn = 0xfffffff;
        while ( i != c - 1 )
        {
            while ( count != t )
            {
                i++;
                if ( i == c )
                    break;
                cnt[ v[ i ].num ]++;
                if ( cnt[ v[ i ].num ] == 1 )
                    count++;
            }
            if ( i == c )
                break;
            while ( cnt[ v[ j ].num ] != 1 )
                cnt[ v[ j++ ].num ]--;
            if ( minn > v[ i ].p - v[ j ].p )
                minn = v[ i ].p - v[ j ].p;
            cnt[ v[ j ].num ]--;
            j++;
            count--;
        }
        printf("%d\n", minn + 1);
    }
}

int main( )
{
//    freopen("2158.in", "r", stdin);
//    freopen("2158.out", "w", stdout);
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        if ( n == 0 && m == 0 )
            break;
        init( );
        work( );
    }
    return 0;
}
